const baseUrl = 'https://box.jiezhui.top';    
// const baseUrl = 'http://www.news2.xin';   

// 定义基础请求路径(后端服务器地址)
export function baseRequest(url, data){
	
		if(ShowLoadingUrl.indexOf(url)>=0){
			uni.showLoading({
				title: '加载中'
			});
		}
		
		if(uni.getStorageSync('token')){
			if(data){
				data.token = uni.getStorageSync('token')
			}else{
				data = {token:uni.getStorageSync('token')}
			}
		}
		let baseDefaultOpts = {
			url: baseUrl+url+'?appid='+uni.getAccountInfoSync().miniProgram.appId+'&skey='+uni.getStorageSync('skey')+'&fappid='+uni.getStorageSync('fappid'),
			// url: baseUrl+url+'?appid=wx98a058ac0db3a48a&skey='+uni.getStorageSync('skey'),
			// 请求接口地址
			data: data,
			method: 'post',
			// 配置请求头
			dataType: 'json',
			}
			let promise = new Promise(function(resolve, reject) {
				uni.request(baseDefaultOpts).then(
					(res) => {
					if(ShowLoadingUrl.indexOf(url)>=0){
						setTimeout(function () {
						  uni.hideLoading();
						}, 200);
												
					}
						resolve(res[1].data)
					}
				).catch(
					(response) => {
						reject(response)
					}
				)
			})
			return promise	
};


const ShowLoadingUrl = [
	'/wxapp/bizhi/indexBizhi.html',
	'/wxapp/bizhi/getZTheme.html',
	'/wxapp/bizhi/getGongzhongList.html',
	'/wxapp/bizhi/getZThemeList.html',
	'/wxapp/tool/getRecommendXcx.html'
]




